package com.finger.forest.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.finger.forest.R;
import com.finger.forest.model.VoiceListModel;
import com.finger.forest.utils.VoiceWidthUtil;

import java.util.List;

/**
 * @author jzj
 * @date 2021/3/10
 * @desc
 */
public class ChatMessageAdapter extends BaseMultiItemQuickAdapter<ChatMultiItemEntity, BaseViewHolder> {
    public ChatMessageAdapter(List<ChatMultiItemEntity> data) {
        super(data);
        addItemType(ChatMultiItemEntity.TYPE_SEND, R.layout.chat_send_view);
        addItemType(ChatMultiItemEntity.TYPE_RECEIVE, R.layout.chat_receive_view);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChatMultiItemEntity item) {
        int type = item.getItemType();
        switch (type) {
            //发送的
            case ChatMultiItemEntity.TYPE_SEND:
                VoiceListModel.FileListBean sendVoiceListModel = item.getSendVoiceListModel();
                if (null != sendVoiceListModel) {
                    ImageView iv = helper.getView(R.id.tvSendVoice);
                    ViewGroup.LayoutParams lp = iv.getLayoutParams();
                    lp.width = VoiceWidthUtil.calVoiceWidth1(sendVoiceListModel.getFileSize());//计算气泡宽度
                    iv.setLayoutParams(lp);//设置语音气泡宽度
                    helper.addOnClickListener(R.id.tvSendVoice);
                }
                break;

            //接收的
            case ChatMultiItemEntity.TYPE_RECEIVE:
                VoiceListModel.FileListBean receiveVoiceListModel = item.getSendVoiceListModel();
                ImageView iv = helper.getView(R.id.tvReceive);
                ViewGroup.LayoutParams lp = iv.getLayoutParams();
                lp.width = VoiceWidthUtil.calVoiceWidth1(receiveVoiceListModel.getFileSize());//计算气泡宽度
                iv.setLayoutParams(lp);//设置语音气泡宽度
                helper.addOnClickListener(R.id.tvReceive);
                break;

            default:
                break;
        }
    }
}
